'use strict';

stareal
    .controller("MessageController", function ($scope, $api, $stateParams, $state, $lazyLoader,$alert) {
      $scope.kind=$stateParams.kind;
        var h=$(window).height()-2.8*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
      var refresh=function(){
          if($scope.kind==1){//回复
              $scope.replaygoods = new $lazyLoader("app/notify/retrieve", {kind:$scope.kind},true);
              $scope.replaygoods.nextPage();
          }else if($scope.kind==2){//点赞
              $scope.zangoods = new $lazyLoader("app/notify/retrieve", {kind:$scope.kind},true);
              $scope.zangoods.nextPage();
          }else if($scope.kind==3){//通知
              $scope.GAOgoods = new $lazyLoader("app/notify/retrieve", {kind:$scope.kind},true);
              $scope.GAOgoods.nextPage();
          }
      }
        refresh();
       $scope.navSwitch=function(index){
           $scope.kind=index;
          // refresh();
           //location.reload();
           $state.go('my.Message',{kind:index});
       }
        //设为已读
        $scope.goComment = function (id,state,notify_id,index,type) {
           if(type!=undefined&&type!=null&&type!=''){
               $state.go('main.viewallreply',{comment_id:id,commentType:type});
           }else{
               $state.go('main.allreply',{comment_id:id});
           }

            if(state=='未读'){
                $api.get("app/notify/setRead",{notify_id:notify_id},true)
                    .then(function (ret) {
                        $scope.replaygoods.items[index].state='已读';
                    })
            }
        }
        $scope.goCommentxing = function (id,state,notify_id,index,type) {
            if(type=='order'){
                $state.go('my.order',{id:id})
            }
            if(type=='productorder'){
                $state.go('my.product_order',{id:id})
            }
            if(state=='未读'){
                $api.get("app/notify/setRead",{notify_id:notify_id},true)
                    .then(function (ret) {
                        $scope.GAOgoods.items[index].state='已读';
                    })
            }
        }
        $scope.goActivexing=function(id,state,notify_id,index,type){
            if(state=='未读'){
                $api.get("app/notify/setRead",{notify_id:notify_id},true)
                    .then(function (ret) {
                        $scope.GAOgoods.items[index].state='已读';
                    })
            }
            $state.go('main.activedetail',{id:id})
        }
        //设为已读
        $scope.zangoComment = function (id,state,notify_id,index,type) {
            // if(type!=undefined&&type!=null&&type!=''){
            //     $state.go('main.viewallreply',{comment_id:id,commentType:type});
            // }else{
            //     $state.go('main.allreply',{comment_id:id});
            // }
            $state.go('main.viewallreply',{comment_id:id})
            if(state=='未读'){
                $api.get("app/notify/setRead",{notify_id:notify_id},true)
                    .then(function (ret) {
                        $scope.zangoods.items[index].state='已读';
                    })
            }
        }
    });